//可迭代对象 const arr = [1,2,3,4]  
// 迭代器工厂函数 arr[Symbol.iterator]
// 迭代器arr[Symbol.iterator]()
//迭代 arr[Symbol.iterator]()()

class Counter {
  constructor(limit) {
    this.count = 1
    this.limit = limit
  }
  next() {
    if(this.count <= this.limit) {
      return {done: false, value: this.count++}
    }else {
      return {done: true, value: undefined}
    }
  }
  [Symbol.iterator]() {
    return this
  }
}
let counter = new Counter(5)
for(let item of counter){
  console.log(item)
}
for(let item of counter){
  console.log(item)
}